package com.irdstudio.efp.report.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.report.service.dao.ZxbsLoanRepayPlanDao;
import com.irdstudio.efp.report.service.domain.ZxbsLoanRepayDetail;
import com.irdstudio.efp.report.service.domain.ZxbsLoanRepayPlan;
import com.irdstudio.efp.report.service.facade.ZxbsLoanRepayPlanService;
import com.irdstudio.efp.report.service.vo.ZxbsLoanRepayPlanVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 服务实现
 *
 * @author gcb
 * @date 2020-07-28
 */
@Service("zxbsLoanRepayPlanService")
public class ZxbsLoanRepayPlanServiceImpl implements ZxbsLoanRepayPlanService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(ZxbsLoanRepayPlanServiceImpl.class);

    @Autowired
    private ZxbsLoanRepayPlanDao zxbsLoanRepayPlanDao;

    /**
     * 新增数据
     *
     * @param zxbsLoanRepayPlanVo
     * @return
     */
    @Override
    public int insert(ZxbsLoanRepayPlanVO zxbsLoanRepayPlanVo) {
        logger.debug("当前新增数据为:" + zxbsLoanRepayPlanVo.toString());
        int num = 0;
        try {
            ZxbsLoanRepayPlan zxbsLoanRepayPlan = new ZxbsLoanRepayPlan();
            beanCopy(zxbsLoanRepayPlanVo, zxbsLoanRepayPlan);
            num = zxbsLoanRepayPlanDao.insert(zxbsLoanRepayPlan);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param zxbsLoanRepayPlanVo
     * @return
     */
    @Override
    public int deleteByPk(ZxbsLoanRepayPlanVO zxbsLoanRepayPlanVo) {
        logger.debug("当前删除数据条件为:" + zxbsLoanRepayPlanVo);
        int num = 0;
        try {
            ZxbsLoanRepayPlan zxbsLoanRepayPlan = new ZxbsLoanRepayPlan();
            beanCopy(zxbsLoanRepayPlanVo, zxbsLoanRepayPlan);
            num = zxbsLoanRepayPlanDao.deleteByPk(zxbsLoanRepayPlan);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + zxbsLoanRepayPlanVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param zxbsLoanRepayPlanVo
     * @return
     */
    @Override
    public int updateByPk(ZxbsLoanRepayPlanVO zxbsLoanRepayPlanVo) {
        logger.debug("当前修改数据为:" + zxbsLoanRepayPlanVo.toString());
        int num = 0;
        try {
            ZxbsLoanRepayPlan zxbsLoanRepayPlan = new ZxbsLoanRepayPlan();
            beanCopy(zxbsLoanRepayPlanVo, zxbsLoanRepayPlan);
            num = zxbsLoanRepayPlanDao.updateByPk(zxbsLoanRepayPlan);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + zxbsLoanRepayPlanVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inZxbsLoanRepayPlanVo
     * @return
     */
    @Override
    public ZxbsLoanRepayPlanVO queryByPk(ZxbsLoanRepayPlanVO inZxbsLoanRepayPlanVo) {
        logger.debug("当前查询参数信息为:" + inZxbsLoanRepayPlanVo);
        try {
            ZxbsLoanRepayPlan queryZxbsLoanRepayPlan = new ZxbsLoanRepayPlan();
            beanCopy(inZxbsLoanRepayPlanVo, queryZxbsLoanRepayPlan);
            ZxbsLoanRepayPlan queryRslZxbsLoanRepayPlan = zxbsLoanRepayPlanDao.queryByPk(queryZxbsLoanRepayPlan);
            if (Objects.nonNull(queryRslZxbsLoanRepayPlan)) {
                return beanCopy(queryRslZxbsLoanRepayPlan, new ZxbsLoanRepayPlanVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public int insertOrUpdate(List<ZxbsLoanRepayPlanVO> list) throws Exception {
        return zxbsLoanRepayPlanDao.insertOrUpdate((List<ZxbsLoanRepayPlan>) beansCopy(list, ZxbsLoanRepayPlan.class));
    }

    @Override
    public List<ZxbsLoanRepayPlanVO> queryMinOverdueStmtDates(List<String> list) throws Exception {
        return (List<ZxbsLoanRepayPlanVO>) beansCopy(this.zxbsLoanRepayPlanDao.queryMinOverdueStmtDates(list), ZxbsLoanRepayPlanVO.class);
    }

    @Override
    public Integer queryCurrentTerm(String date, String billNo) {
        return this.zxbsLoanRepayPlanDao.queryCurrentTerm(date, billNo);
    }

    @Override
    public List<ZxbsLoanRepayPlanVO> queryRepayPlansByRefNbr(List<String> list) throws Exception {
        return (List<ZxbsLoanRepayPlanVO>) beansCopy(this.zxbsLoanRepayPlanDao.queryRepayPlansByRefNbr(list), ZxbsLoanRepayPlanVO.class);
    }

    @Override
    public List<ZxbsLoanRepayPlanVO> queryRepayPlanByRefNbrAndStatus(ZxbsLoanRepayPlanVO loanRepayPlanVO) throws Exception {
        return (List<ZxbsLoanRepayPlanVO>) beansCopy(this.zxbsLoanRepayPlanDao.queryRepayPlanByRefNbrAndStatus(beanCopy(loanRepayPlanVO, new ZxbsLoanRepayPlan())), ZxbsLoanRepayPlanVO.class);
    }
}
